package com.yuyou.fn.timer.task;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHander;
import com.xxl.job.core.log.XxlJobLogger;
import com.yuyou.fn.tradingservice.entity.ServiceOrderItem;
import com.yuyou.fn.tradingservice.service.IServiceOrderItemService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * Created by lzh on 2017/08/14.
 */
@JobHander(value="CancelServiceOrderItemTask")
@Component
public class CancelServiceOrderItemTask extends IJobHandler {



    @Resource
    private IServiceOrderItemService serviceOrderItemService;

    @Override
    public ReturnT<String> execute(String... strings) throws Exception {
        Calendar cal = Calendar. getInstance ();
        cal.add(Calendar.HOUR,-1);
        Date date=cal.getTime();
        List<ServiceOrderItem> serviceOrderItemList =serviceOrderItemService.findByLessCreateTimeAndStatus(date,0);
        for(ServiceOrderItem serviceOrderItem : serviceOrderItemList){
            try{
                serviceOrderItemService.cancelServiceOrderItem(serviceOrderItem.getOrderItemId(),4);
            }catch (Exception e){
                XxlJobLogger.log("撤销订单"+ serviceOrderItem.getOrderItemId()+"失败",e);
            }

        }
        return  ReturnT.SUCCESS;
    }

}
